package st0002;

class Solution {//有点乱，竟然通过了,Solution2更合理
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        int q=0;
        ListNode result=new ListNode();
        ListNode m=result;
        while (l1.next!=null&&l2.next!=null){
            int p=l1.val+l2.val+q;
            q=p/10;
            m.val=p%10;
            m.next=new ListNode();
            m=m.next;
            l1=l1.next;
            l2=l2.next;
        }
        while (l1.next!=null){
            int p=l1.val+l2.val+q;
            q=p/10;
            m.val=p%10;
            m.next=new ListNode();
            m=m.next;
            l1=l1.next;
            l2.val=0;
        }
        while (l2.next!=null){
            int p=l1.val+l2.val+q;
            q=p/10;
            m.val=p%10;
            m.next=new ListNode();
            m=m.next;
            l2=l2.next;
            l1.val=0;
        }
        if(l1.next==null&&l2.next==null){
            int p=l1.val+l2.val+q;
            q=p/10;
            m.val=p%10;
            if(q>0){
                m.next=new ListNode(q);
            }
            return result;
        }
        return result;
    }
    public static void main(String[] args) {
        Solution a = new Solution();
        int q=34;
        int b=q/10;
        int c=0;
    }
}
